Stormin' The Castle

node.js

Autostart Node.js Apps at Boot

by John Robinson @johnrobinsn

Launching node.js apps at boot is easy with PM2 (Process Manager 2). PM2 is a process manager for Node.js applications. It allows you to keep your apps alive and has a built-in load balancer. PM2 also has a feature to start your app at boot.

Recently I was writing some home automation software using node.js on a raspberry pi and I needed my node.js app to start at boot. It can be a little tricky to get node apps to start at boot especially if you're using a node version manager.

Here is a good link on setting things up [https://www.npmjs.com/package/pm2]

If you're using systemd on your system, you can use the following to autostart PM2 at boot.

sudo env PATH=$PATH:/usr/bin pm2 startup systemd -u <user_id> --hp /home/<user_id>

PM2 will then handle autostarting your node.js apps that you can configure by running 'pm2 start <yourapp.js>' and then running 'pm2 save'.


Share on Twitter |  Discuss on Twitter

John Robinson © 2022-2025